package com.tl.commonlibrary.ui.web;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.tl.commonlibrary.ui.widget.TitleBar;
import com.tl.share.share.ShareBean;
import com.tl.share.share.ShareUtils;

/**
 * Created by Administrator on 2017/7/4 0004.
 */

public abstract class ShareWebActivity extends WebActivity {

    public static final Intent newIntent(Context context, String url, String title) {
        Intent intent = WebActivity.newIntent(context, url, title, false, null, WebModel.FROM_TYPE_DEFAULT);
        return intent;
    }

    protected View shareBtn;
    protected ShareBean shareBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setShareButton();
    }

    private void setShareButton() {
        TitleBar titleBar = getTitleBar();
        if (titleBar == null) {
            return;
        }
        shareBtn = titleBar.addAction(new TitleBar.ImageAction(com.tl.commonlibrary.R.drawable.ic_share) {
            @Override
            public void performAction(View view) {
                if (shareBean != null) {
                    ShareUtils.show(context, shareBean);
                }
                onShareClicked();
            }
        });
        shareBtn.setVisibility(View.GONE);

    }

    public void showShareBtn() {
        shareBtn.setVisibility(View.VISIBLE);
    }

    public abstract void onShareClicked();
}
